#!/dis/sh -n

# Start script for octopus PC

load std

dom=lsub.org
sysname=`{cat /dev/sysname}
user=`{cat /dev/user}

ndb/dns
ndb/cs
or {ftest -f /keydb/signerkey} {echo 'auth: need to use createsignerkey(8)' >[1=2]; exit nosignerkey}
or {ftest -f /keydb/keys} {echo 'auth: need to create /keydb/keys' >[1=2]; exit nokeys}
auth/keyfs -n /keydb/nvr

PC=$sysname.$dom
pcip=`{ndb/dnsquery $PC | sed 's/.*ip	//'}
grep -v '^sys=pc' /lib/ndb/octopus > /lib/ndb/_octopus
echo 'sys=pc ip=127.0.0.1' >>/lib/ndb/_octopus
echo 'sys=pc ip='^$pcip >>/lib/ndb/_octopus
mv /lib/ndb/_octopus /lib/ndb/octopus
mkdir -p /term /pc /devs /devs/pc

echo starting octopus PC $PC at $pcip | tee /n/log/octopus
echo listening for inflogin, infkey, infsigner, infcsinger, styx, op, rop, ...
listen -v -t -A 'tcp!*!inflogin' {auth/logind>[2]/n/log/octopus& }
listen -v -t -A 'tcp!*!infkey' {auth/keysrv>[2]/n/log/octopus&}
listen -v -t -A 'tcp!*!infsigner' {auth/signer>[2]/n/log/octopus&}
listen -v -t -A 'tcp!*!infcsigner' {auth/countersigner>[2]/n/log/octopus&}
listen -tv 'tcp!*!styx' {export /pc>[2]/n/log/octopus&}

bind -c '#₪' /srv
9srvfs pc / &

listen -tv 'tcp!*!op' {o/oxport /pc >[2]/n/log/octopus&}
listen -tv 'tcp!*!rop' {o/ofs -A -m auto /fd/0 >[2]/n/log/octopus&}
echo starting registry
svc/registry>[2]/n/log/octopus
auth/keyfs -n /keydb/nvr	# registry gets rid of it. relaunch
plumber >[2]/n/log/octopus
o/watcher -v -t 120 >[2]/n/log/octopus
o/plumbing  netget { /dis/o/newterm $msg }

# local services. Customize per-user
bind -ac /dis/o/$emuhost /dis/o
sysname=pc
bind -c /term /term
mkdir -p /term/^(what where who music view voice print mail fs)
bind -c /n/planb/what /term/what
bind -c /n/planb/where /term/where
bind -c /n/planb/who /term/who
bind -c /n/music /term/music
bind -c /n/local/mail/box/$user /term/mail
bind -c '#U*' /term/fs
o/netget -r /mnt/registry what 'path /what' who 'path /who' where 'path /where' music 'path /music' mail 'path /mail' fs 'path /fs'

bind -c /term /devs/pc
bind -c '#U' /pc
bind -c /devs /pc/devs
bind -c /mnt /pc/mnt

wm/sh -n
